﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Windows.Forms;

namespace SPMigrationOracleUtility
{
    class mapping_posts
    {
        public  string map_name { set; get; }
        public  string map_desc { set; get; }

        public int lst_cnt { set; get; }
        public int lib_cnt { set; get; }

        int ListSelectioncnt = 0;
        int Libraryselcount = 0;

        int cnt;
        
        public void Map_List_Posted(ListItemCollection coll)
        {
            ListItemCollection liMapList = coll;
            map_name = "map";
            map_desc = "desc";

        }
        
        public void Map_Col_List_Posted(ListItemCollection coll)
        {
            ListItemCollection liMapCol = coll;
                      
        }
        
        public void MappingInit(ListBox lSrc,ComboBox cSrc,ListBox lDesc,ComboBox cDest)
        {
            cSrc.Items.Clear();
            cDest.Items.Clear();

            //cDest.DisplayMember = "Text";
            foreach (object obj in lDesc.Items)
            {
                cDest.Items.Add(obj);

            }

            if (cDest.Items.Count > 0)
                cDest.SelectedIndex = 0;

            foreach (object obj in lSrc.Items)
            {
                cSrc.Items.Add(obj);
            }
            if (cSrc.Items.Count > 0)
                cSrc.SelectedIndex = 0;
        }

        public object Btn_DbForward(RadioButton rd, ListBox lstDBs, ListBox lstDB, Button btnFrd, Button btnBrd, Button btnNextPnl3)
        {
            string str = rd.Name;

            cnt = lstDB.Items.Count;

            if (str == "rdBtnTables" || str == "optTables")
            {
               

                if (cnt == 2)
                {
                    btnFrd.Enabled = false;
                    btnBrd.Enabled = true;
                }

                else if (cnt == 1)
                {
                    btnNextPnl3.Enabled = true;
                    btnBrd.Enabled = true;
                }
                else
                {
                    btnFrd.Enabled = true;
                    btnBrd.Enabled = false;
                }

            }

            else
            {
                if (cnt == 1)
                {
                    btnFrd.Enabled = false;
                    btnBrd.Enabled = true;
                    btnNextPnl3.Enabled = true;
                }
                else
                {
                    btnFrd.Enabled = true;
                    btnBrd.Enabled = false;
                }
            }

            return lstDB;
        }

        public void MoveData( Button btnListLibAdd ,ListBox objListsrc, ListBox objListDest, int val)
        {

            bool adddata1 = false;
            string type1 = "";

            try
            {
                ListItemPair objList = (ListItemPair)objListsrc.SelectedItem;
                if (objList.ListTemplate == Microsoft.SharePoint.Client.BaseType.DocumentLibrary)
                {
                    Libraryselcount = Libraryselcount + val;
                }
                else
                {
                    ListSelectioncnt = ListSelectioncnt + val;
                }

                if (ListSelectioncnt == 0 && Libraryselcount == 1)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = true;

                }
                else if (ListSelectioncnt == 1 && Libraryselcount == 0)
                {

                    adddata1 = true;
                    btnListLibAdd.Enabled = true;

                }
                else if (ListSelectioncnt == 2 && Libraryselcount == 0)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = false;

                }
                else if (ListSelectioncnt == 1 && Libraryselcount == 1)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = false;
                }
                else if (ListSelectioncnt == 0 && Libraryselcount == 0)
                {
                    adddata1 = true;
                    // btnListLibRem.Enabled = false;
                }
                else
                {
                    Libraryselcount = 1;
                    MessageBox.Show("Invalid Mapping.");
                }

                if (adddata1)
                {
                    objListDest.Items.Add(objList);
                    objListDest.DisplayMember = "Text";
                    int selectedIndex = Convert.ToInt32(objListsrc.SelectedIndex);
                    objListsrc.Items.RemoveAt(selectedIndex);
                }
            }
            catch (SystemException ee)
            {
                MessageBox.Show("Select the valid List or Library");
            }


           // Step4Enable();
        }

        //public void MoveData_FWD(Button btnListLibAdd, ListBox objListsrc, ListBox objListDest,int lstCnt,int libCnt)
        //{

        //    bool adddata1 = false;
        //    string type1 = "";
        //    Libraryselcount = libCnt;
        //    ListSelectioncnt = lstCnt;
        //    try
        //    {

        //        //ListItemPair_SP li = (ListItemPair_SP)objListDest.SelectedItem;

        //        //if(li.ListTemplate == "DocumentLibrary")

                
        //        ListItemPair objList = (ListItemPair)objListsrc.SelectedItem;
        //        //List  lis = Convert.ToString(objListsrc.SelectedItem;
        //        if (objList.ListTemplate == Microsoft.SharePoint.Client.BaseType.DocumentLibrary)
        //        {
        //            Libraryselcount = Libraryselcount + 1;
        //        }

        //        //if (li.ListTemplate == "DocumentLibrary")
        //        //{
        //        //    Libraryselcount = Libraryselcount + 1;
        //        //}
        //        else
        //        {
        //            ListSelectioncnt = ListSelectioncnt + 1;
        //        }

        //        if (ListSelectioncnt == 0 && Libraryselcount == 1)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = true;

        //        }
        //        else if (ListSelectioncnt == 1 && Libraryselcount == 0)
        //        {

        //            adddata1 = true;
        //            btnListLibAdd.Enabled = true;

        //        }
        //        else if (ListSelectioncnt == 2 && Libraryselcount == 0)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = false;

        //        }
        //        else if (ListSelectioncnt == 1 && Libraryselcount == 1)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = false;
        //        }
        //        else if (ListSelectioncnt == 0 && Libraryselcount == 0)
        //        {
        //            adddata1 = true;
        //            // btnListLibRem.Enabled = false;
        //        }
        //        else
        //        {
        //            Libraryselcount = 1;
        //            MessageBox.Show("Invalid Mapping.");
        //        }

        //        if (adddata1)
        //        {
        //            objListDest.Items.Add(objList);
        //            objListDest.DisplayMember = "Text";
        //            int selectedIndex = Convert.ToInt32(objListsrc.SelectedIndex);
        //            objListsrc.Items.RemoveAt(selectedIndex);
        //        }
        //    }
        //    catch (SystemException ee)
        //    {
        //        MessageBox.Show("Select the valid List or Library");
        //    }

        //    lst_cnt = ListSelectioncnt;
        //    lib_cnt = Libraryselcount;
        //    // Step4Enable();
        //}

        //public void MoveData_BWD(Button btnListLibAdd, ListBox objListsrc, ListBox objListDest, int lstCnt, int libCnt)
        //{

        //    bool adddata1 = false;
        //    string type1 = "";
        //    Libraryselcount = libCnt;
        //    ListSelectioncnt = lstCnt;
        //    try
        //    {

        //        ListItemPair_SP objList = (ListItemPair_SP)objListDest.SelectedItem;

        //        //foreach (ListItemPair_SP li in (ListItemPair_SP)objListDest.Items)
        //        //{

        //        //}


        //        if (objList.ListTemplate == "DocumentLibrary")
        //        {
        //            Libraryselcount = Libraryselcount + 1;
        //        }
        //        else
        //        {
        //            ListSelectioncnt = ListSelectioncnt + 1;
        //        }

        //        if (ListSelectioncnt == 0 && Libraryselcount == 1)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = true;

        //        }
        //        else if (ListSelectioncnt == 1 && Libraryselcount == 0)
        //        {

        //            adddata1 = true;
        //            btnListLibAdd.Enabled = true;

        //        }
        //        else if (ListSelectioncnt == 2 && Libraryselcount == 0)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = false;

        //        }
        //        else if (ListSelectioncnt == 1 && Libraryselcount == 1)
        //        {
        //            adddata1 = true;
        //            btnListLibAdd.Enabled = false;
        //        }
        //        else if (ListSelectioncnt == 0 && Libraryselcount == 0)
        //        {
        //            adddata1 = true;
        //            // btnListLibRem.Enabled = false;
        //        }
        //        else
        //        {
        //            Libraryselcount = 1;
        //            MessageBox.Show("Invalid Mapping.");
        //        }

        //        if (adddata1)
        //        {
        //            objListDest.Items.Add(objList);
        //            objListDest.DisplayMember = "Text";
        //            int selectedIndex = Convert.ToInt32(objListsrc.SelectedIndex);
        //            objListsrc.Items.RemoveAt(selectedIndex);
        //        }
        //    }
        //    catch (Exception  ee)
        //    {
        //        MessageBox.Show(ee.Message);
        //    }

        //    lst_cnt = ListSelectioncnt;
        //    lib_cnt = Libraryselcount;
        //    // Step4Enable();
        //}
 
    }
}
